#include<iostream>
using std::endl;
using std::cout;

class Base1
{
public:
    virtual void fun()       
    {   
		cout<<"--Base1--\n";  
	}
};

class Base2
{
public:
    void fun()               	
    {   
		cout<<"--Base2--\n"; 
	}
};

class Derived
:public Base1
,public Base2
{
public:
    void fun()
    {   
        cout<<"--Derived--\n";  
    }
};

class Test
: public Derived
{
public:
    void fun(){
        cout << "Test::fun" << endl;
    }
};

void test0(){
    Test tt;
    Derived * p = &tt;
    p->fun();
}

int main()
{
    test0();
    cout << endl;
    Base1 obj1, *ptr1;   
    Base2 obj2, *ptr2;   	
    Derived obj3; 
	
    ptr1=&obj1;   //Base1*指针指向Base1类对象      	
    ptr1->fun();  //通过虚表调用自己的虚函数    --Base1--
    
    ptr2=&obj2;   //Base2*指针指向Base2类对象      	
    ptr2->fun();  //不通过虚表，调用普通成员函数  --Base2--
    
    ptr1=&obj3;   //Base1*指针指向Derived类对象      	
    ptr1->fun();  //通过虚表调用派生类覆盖的虚函数 --Derived--
    
    ptr2=&obj3;  //Base2*指针指向Derived类对象   	
    ptr2->fun(); //对于Base2类func函数是普通成员函数 不通过虚表 --Base2--
    return 0;	                  
}
